In this Rmarkdown document we are going to create the spatial pannels necessary for Figure 2.
To do this we will load the MAGIC-denoised data to better visualize genes and ease with the annotation when using specific marker genes. The MAGIC denoised data was generated in the script spatial_transcriptomics/CD4-analysis/MAGIC_denoising.Rmd.
library(Seurat)
library(ggpubr)
library(cowplot)
library(dplyr)
library(ggplot2)
library(SPATA2)
Loading necessary paths and parameters
set.seed(123)
source(here::here("misc/paths.R"))
source(here::here("utils/bin.R"))
"{fig2}/{plt_dir}" %>%
glue::glue() %>%
here::here() %>%
dir.create(path = .,
showWarnings = FALSE,
recursive = TRUE)
"{fig2}/{robj_dir}" %>%
glue::glue() %>%
here::here() %>%
dir.create(path = .,
showWarnings = FALSE,
recursive = TRUE)
The data used in this Rmarkdown document comes from 03-clustering_integration.Rmd where the data was integrated.
merged_se <- "misc/{robj_dir}/20220215_tonsil_atlas_spatial_seurat_obj.rds" %>%
glue::glue() %>%
here::here() %>%
readRDS(file = .)
# Load SPOTlight data
spotlight_ls <- "{cd4}/{robj_dir}/spotlight_ls_cd4_new.rds" %>%
glue::glue() %>%
here::here() %>%
readRDS(file = .)
# Load SPOTlight data
nm_df <- "{cd4}/{robj_dir}/cd4_nm_df.rds" %>%
glue::glue() %>%
here::here() %>%
readRDS(file = .)
decon_mtrx <- spotlight_ls[[2]]
decon_mtrx <- decon_mtrx[, colnames(decon_mtrx) != "res_ss"]
# Set as 0 cell types predicted to be under 3 % of the spot
decon_mtrx[decon_mtrx < 0.03] <- 0
Change column names
new_cn <- data.frame(mod_nm = colnames(decon_mtrx)) %>%
dplyr::left_join(nm_df, by = "mod_nm") %>%
dplyr::mutate(plt_nm = dplyr::if_else(is.na(plt_nm), mod_nm, plt_nm)) %>%
dplyr::distinct() %>%
dplyr::pull(plt_nm)
colnames(decon_mtrx) <- new_cn
We are going to add the deconvolution to the Seurat object.
merged_se@meta.data <- cbind(merged_se@meta.data, decon_mtrx)
Subset sample of interest
sample_id <- "esvq52_nluss5"
sp_sub <- merged_se[, merged_se@meta.data$gem_id == sample_id]
sp_sub@images <- sp_sub@images[Seurat::Images(sp_sub) == sample_id]
Look at the location of each cell type in each slice separately
# Iterate over cell types
ct_int <- c("Naive", "GC-Tfh-0X40", "GC-Tfh-SAP", "Tfh-LZ-GC")
nm_donor <- id_sp_df %>% dplyr::filter(gem_id == sample_id) %>% dplyr::pull(donor_id)
# Iterate over cell types
ct_plt_ls <- lapply(ct_int, function(i) {
tmp_plt <- Seurat::SpatialFeaturePlot(
object = merged_se,
features = i,
alpha = c(0, 1),
images = sample_id,
image.alpha = 1) +
ggplot2::scale_fill_gradientn(
colors = heat.colors(10, rev = TRUE)) +
ggplot2::scale_alpha(range = c(0, 1)) +
ggplot2::labs(title = stringr::str_wrap(string = i,
width = 25),
fill = "") +
ggplot2::theme(
plot.title = ggplot2::element_text(
hjust = 0.5,
size = 20,
face = "bold"))
return(tmp_plt)
})
(plt_arr <- cowplot::plot_grid(
plotlist = ct_plt_ls,
axis = "trbl",
align = "hv",
nrow = 2,
ncol = 2))